using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Dojo;

namespace DojoCompressorView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            compressButton.Enabled = false;
        }

        private void dojoHomeBrowseButton_Click(object sender, EventArgs e)
        {
            dojoHomeSelected = false;
            folderBrowser.ShowDialog();
            dojoHomeTextBox.Text = dojoHome =  folderBrowser.SelectedPath;
            if(dojoHome != string.Empty)
                dojoHomeSelected = true;
            enableCompressButton();
        }

        private void codeRootBrowseButton_Click(object sender, EventArgs e)
        {
            codeRootSelected = false;
            folderBrowser.ShowDialog();
            codeRootTextBox.Text = codeRoot =  folderBrowser.SelectedPath;
            if(codeRoot != string.Empty)
                codeRootSelected = true;
            enableCompressButton();
        }

        private void destinationBrowseButton_Click(object sender, EventArgs e)
        {
            destinationSelected = false;
            folderBrowser.ShowDialog();
            destinationTextBox.Text = destination =  folderBrowser.SelectedPath;
            if(destination != string.Empty)
                destinationSelected = true;
            enableCompressButton();
        }

        private void destinationTextBox_TextChanged(object sender, EventArgs e)
        {
            destination = destinationTextBox.Text;
            if (destination != string.Empty)
                destinationSelected = true;
            enableCompressButton();
        }

        private void button4_Click(object sender, EventArgs e)
        {
              FileSearcher searcher = new FileSearcher(dojoHome,codeRoot);
              FileResolver resolver = new FileResolver();   
              Copier copier = new Copier(dojoHome);  
              DojoCompressor compressor = new DojoCompressor(searcher,resolver,copier);
              compressor.Compress(destination);
              MessageBox.Show("Done !");
        }

        private void enableCompressButton() {
            compressButton.Enabled = false;
            if(dojoHomeSelected && codeRootSelected && destinationSelected) {
                compressButton.Enabled = true;
            }
        }
        
        private string dojoHome;
        private string codeRoot;
        private string destination;
        private Hashtable cachedUrls;
        private bool dojoHomeSelected;
        private bool codeRootSelected;
        private bool destinationSelected;

        
    }
}